// 打包测试数据
let { Article, User, Cart, Order } = require("../model");
console.log(11);

const fs = require("fs");
let arr = [Article, User, Cart];

function exportData() {
  arr.forEach((fn) => {
    console.log(fn);
    fn.find().then((r) => {
      fs.writeFile(
        "./backup/" + fn.modelName + ".json",
        JSON.stringify(r),
        function () {
          console.log(fn.modelName + "表 数据导出成功");
        }
      );
    });
  });
}
function importData() {
  arr.forEach((fn) => {
    fs.readFile("./backup/" + fn.modelName + ".json", function (err, data) {
      let obj = JSON.parse(data);
      fn.insertMany(obj).then((r) => {
        console.log(fn.modelName + "表 数据导入成功");
      });
    });
  });
}
// importData();
// exportData();
module.exports = { exportData, importData };
